/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.bayu.controller;

/**
 *
 * @author Bayu
 */
import com.bayu.common.lib.CommonUtil;
import com.bayu.services.dao.TStockDao;
import com.bayu.services.entity.TStock;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 *
 * @author Bayu
 */
@Controller
@RequestMapping("/tstock-update.htm")
public class TStockUpdate {
    TStockDao dao;

    @Autowired
    private void setTStockDao(TStockDao tStockDao){
      this.dao = tStockDao;
    }

    @RequestMapping(method = RequestMethod.GET)
    public void displayForm(ModelMap map,String id){
        List list = this.dao.getById(id);
        map.addAttribute("data", list);
    }

    @RequestMapping(method = RequestMethod.POST)
    public String proccessForm(@ModelAttribute("TStock") TStock tStock , BindingResult result,ModelMap map, String idStock,HttpServletRequest req){
         tStock.setIdStock(idStock);
         this.dao.update(tStock);
         return "redirect:view-tstock-data.htm?msg=Data has been updated";
    }
}

